<template>
  <div>
    <el-card>
      <!-- 搜索 -->
      <el-form :inline="true" :model="orderSerach" class="demo-form-inline">
        <el-form-item label="订单号:">
          <el-input
            v-model="orderSerach.orderSn"
            placeholder="请输入订单号"
            clearable
            @change="getOrder"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input
            v-model="orderSerach.contactPhone"
            placeholder="请输入手机号"
            clearable
            @change="getOrder"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
        </el-form-item>
      </el-form>
      <!-- 表格 -->

      <el-table :data="orderlist" border style="width: 100%">
        <el-table-column prop="orderSn" label="订单号" width="180">
        </el-table-column>
        <el-table-column prop="orderState" label="订单状态" width="180">
          <template slot-scope="scoped">
            <div>
              <el-tag v-if="scoped.row.orderState == 0" type="warning"
                >生成成功,等待添加设备</el-tag
              >
              <el-tag v-else-if="scoped.row.orderState == 1"
                >设备添加完成</el-tag
              >
              <el-tag v-else-if="scoped.row.orderState == 2" type="success"
                >订单完成</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="actualPayMoney" label="实际支付金额" width="120">
        </el-table-column>
        <el-table-column prop="needPayMoney" label="下单支付金额" width="120">
        </el-table-column>
        <el-table-column prop="contactAddress" label="配送地址" width="220">
        </el-table-column>
        <el-table-column prop="contactPhone" label="联系人电话" width="120">
        </el-table-column>
        <el-table-column prop="contactName" label="	联系人姓名" width="120">
        </el-table-column>
        <el-table-column prop="isSign" label="是否签收">
          <template slot-scope="scope">
            <div>
              <el-tag v-if="scope.row.isSign == 1" type="success">签收</el-tag>
              <el-tag v-else-if="scope.row.isSign == 2" type="danger"
                >未签收</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="220">
        </el-table-column>
        <el-table-column prop="add_time" label="添加时间" width="220">
        </el-table-column>
        <el-table-column prop="update_time" label="更新数据时间" width="220">
        </el-table-column>
        <el-table-column prop="end_time" label="订单结束时间" width="220">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="300">
          <template slot-scope="scoped">
            <el-button
              type="primary"
              size="mini"
              @click="handlerDevicefenfa(scoped.row.orderSn)"
              >设备分发</el-button
            >
            <el-button
              type="success"
              size="mini"
              @click="handlershowDevice(scoped.row.orderSn)"
              >查看设备</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="orderSerach.pageSize"
          :current-page="orderSerach.pageNumber"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
          class="management_page"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getOrderList } from "../../utils/api";
export default {
  data() {
    return {
      // 订单列表
      orderlist: [],
      //   搜索栏
      orderSerach: {
        orderSn: "",
        contactPhone: "",
        pageNumber: 1,
        pageSize: 10,
        orderType: 2
      },
      // 订单总条数
      count: 0
    };
  },
  created() {
    this.getOrder();
  },
  methods: {
    // 获取订单信息
    getOrder() {
      this.postRequest(getOrderList, this.orderSerach).then(res => {
        if (res.code == 200) {
          this.orderlist = res.data.list;
          this.count = res.data.count;
        }
      });
    },

    // 分页
    handleSizeChange(val) {
      this.orderSerach.pageSize = val;
      this.getOrder();
    },
    handleCurrentChange(val) {
      this.orderSerach.pageNumber = val;
      this.getOrder();
    },

    // 点击设备分发
    handlerDevicefenfa(orderSn) {
      window.sessionStorage.setItem("orderSn", orderSn);
      this.$router.push("/orderdevice");
    },
    // 点击查看设备
    handlershowDevice(orderSn) {
      window.sessionStorage.setItem("orderSn1", orderSn);
      this.$router.push("/kuaidigetdevice");
    }
  }
};
</script>

<style></style>
